package com.scuec.groupfive.Controller;

import com.scuec.groupfive.service.PostMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.util.Date;

@RestController
@RequestMapping("/post")
@CrossOrigin(
        origins = "http://localhost:5173",
        allowedHeaders = "*",
        methods = {RequestMethod.GET, RequestMethod.OPTIONS}
)
public class PostMessageController {
    @Autowired
    private PostMessageService postMessageService;

    @GetMapping("/total-count")
    public int getTotalMessageCount() {
        System.out.println("total-count接口被调用");
        return postMessageService.getTotalMessageCount();
    }

    @GetMapping("/count-by-date")
    public int getMessageCountByDateRange(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        System.out.println("按日期查询接口被调用");
        return postMessageService.getMessageCountByDateRange(startDate, endDate);
    }
}